Flash Article

Time Entry Application: Sample Workflow for Designing and Building Applications in Flash MX Professional 2004

by Paul Gubbay
Macromedia

The Time Entry sample application provides you with a basic workflow for designing and building applications in Flash MX Professional 2004 using data components, forms, and data binding. This article introduces you to the application and provides some basic information on its structure. You will benefit most by looking at the source code, reading the comments, and reviewing the way I use data binding to control the flow of data between the components. All the code within the application is fully documented.

The workflow described in this sample application will be familiar to users with an application development background. Functionality it is split among several classes, each providing a public interface to expose business logic. The code for the entire application is contained within several external ActionScript class files. In addition, the sample makes use of many of the new features of visual data binding.

The Time Entry application accomplishes two goals:

  • Defines a useful framework for developers to build applications that utilize the new features in Flash MX Professional 2004
  • Provides several examples using data components and data binding to integrate data within your Flash application

By the way, this sample application in no way reflects Macromedia's best practices for building Rich Internet Applications. It is simply a work in progress that will continue to evolve as I add new features.

Requirements

To run the Time Entry sample application, you should have Flash MX Professional 2004 and ColdFusion MX installed on the computers you plan to use. You can install ColdFusion MX on a different computer than the one on which you build the Flash application but you will need to update the IP address within the application.

Macromedia Flash MX Professional 2004


Macromedia ColdFusion MX


Download sample files for this tutorial


Contains Flash project file, ActionScript files, Access database, and ColdFusion component

Note: The sample ColdFusion Component gives you the ability to run a query statement against any ColdFusion data source that you have set up on your machine. You should install it to the web root folder only within a development environment behind a secure firewall or on a computer that is not connected to the Internet! If you intend to use this component in a production environment you must take the necessary steps to secure it.

Features of the Time Entry Application

The Time Entry sample application (see Figure 1) demonstrates the following features:

  • Querying an Access database using a Cold Fusion web service
  • Creating calculated fields
  • Embedding a CheckBox within a DataGrid
  • Creating a static data-aware lookup list
  • Creating a dynamic data-aware lookup list
  • Filtering
  • Sorting
  • Creating an update log file (displays data sent between client and server)
  • Saving data and changes offline
  • Adding a reconcile dialog box (reports errors from the server and allows users to fix and resend)

Time Entry sample application and its features

Figure 1. Time Entry sample application and its features

Querying an Access database using a ColdFusion web service: Included with the installation is a sample ColdFusion component (CFC) that allows you easily to query an Access database that has been set up as a ColdFusion data source. The CFC also understands the format of the update packets sent from the RDBMSResolver. It parses the updates, generates the correct SQL statements, and creates a formatted result packet containing any errors or updates that occurred as a result of updating the Access database.

Note: You access the CFC from the sample application as a web service but you could easily switch that to work through Flash Remoting.

Creating calculated fields: The cost field that appears in the DataGrid component is a calculated field. If you modify the hours or the rate field, the cost field automatically updates. It is never included in the update packet because it only resides in memory within the application.

Embedding a CheckBox: The DataGrid component makes it easy to modify Boolean values by embedding a CheckBox within the Billable column. The source code (included with the example) shows how to create this setup.

Creating a static data-aware lookup list: The Services ComboBox contains a list of static values. Selecting a new value updates the selected time entry with a new foreign key value.

Creating a dynamic data-aware lookup list: The Projects ComboBox contains a list of dynamic values pulled from another table within the database. Selecting a new value updates the selected time entry with a new foreign key value.

Filtering: Users can filter records that appear within the DataGrid by changing the dates at the top of the screen.

Sorting: Users can sort data by clicking on any column header.

Creating an update log file: A log entry is generated every time data is saved. The log contains a copy of the update packet that was sent to the server and the result packet that was returned from the server. You can view the Update Log tab, which contains a view of all log entries, by selecting View > Update Log.

Saving data and changes offline: Users can work with data offline or online. Test this functionality as follows:

  1. Click the Load button to retrieve data from the server.
  2. Modify the data (adds, edits, deletes).
  3. Select Settings > Work Offline.
  4. Click the Save button. Your data is saved on your local machine (shared object).
  5. Select Settings > Work Offline again to uncheck the option.
  6. Click the Load button to retrieve data from the server. The data reflects what is on the server (the original data you pulled in Step 1 without your modifications).
  7. Select Settings > Work Offline.
  8. Click the Load button to retrieve data from your local machine (shared object). The data now reflects the changes you made in Step 2.
  9. Select Settings > Work Offline again to uncheck the option.
  10. Click Save to send your updates back to the server.

As you can see, you can work completely disconnected from the server. The DataSet tracks all your changes and continues updating the DeltaPacket. When you are back online the DeltaPacket is sent to the server for processing.

Adding a reconcile dialog box: The reconcile dialog box appears automatically whenever an error (or more than one) is returned from the server as a result of saving data. The dialog box displays the error message from the server and provides you with several options:

  • Discard This Change: When you close the dialog box the changed record reverts to its original state and the update instruction is removed from the DeltaPacket. The following rules apply when you revert a record to its original state:

    • If the record is an insertion that fails on the server, it's removed from the DataSet as if it was never inserted.
    • If the record is a deletion that fails on the server, it's reinserted into the DataSet as if it was never deleted.
    • If the record is a modification that fails on the server, the modified fields are set back to their original values as if they were never modified.
  • Find Record: This option searches for the changed record within the DataSet and makes it the current record. You can then modify the record to fix the error that was reported from the server. (For example, if the server reports that it cannot insert a record with a null ID field, you can enter a valid value for the ID field.)

    After find the record, fix it, and close the dialog box, nothing will appear to happen but actually the changed record with your new modifications will be contained within the current DeltaPacket. The next time you click the Save button it will be sent back to the server.

Note: If you run the application online (hosted on the Macromedia site) you will not be able to save data to the server. Each time you attempt it you will receive an error. You must download the sample application and set it up on your own computer in order to save data to the Access database.

Installing the Time Entry Application

It's relatively straightforward to install the Time Entry sample application.

First set up the project. Unzip time_entry.zip into a folder on your hard drive, called TimeEntry. You should see the following structure:

TimeEntry\TimeEntry.flp (the Flash project file)
TimeEntry\TimeEntry.fla
TimeEntry\TimeEntry.swf
TimeEntry\cfc\RDBMSProcessor.cfc (the ColdFusion component)
TimeEntry\data\TimeEntry.mdb (the Access database)
TimeEntry\src\com\macromedia\timeentry\Application.as
TimeEntry\src\com\macromedia\timeentry\TimeEntry.as
TimeEntry\src\com\macromedia\timeentry\TimeEntryData.as
TimeEntry\src\com\macromedia\timeentry\Reconcile.as
TimeEntry\src\com\macromedia\timeentry\Log.as
TimeEntry\src\com\macromedia\timeentry\Project.as
TimeEntry\src\com\macromedia\timeentry\Client.as

Next set up the ColdFusion component. Add a ColdFusion data source for the Access database (MDB file):

  1. Open ColdFusion administrator.
  2. Click the Data Sources link.
  3. Type TimeEntry in the Data Source Name edit box. Select Microsoft Access from the Driver combo box. Click Add.
  4. Click the Browse button and navigate to the MDB file (TimeEntry\data\TimeEntry.mdb).
  5. Click Submit.
  6. Verify that the new data source has a status "OK."
  7. Save the TimeEntry\cfc\RDBMSProcessor.cfc file to the web root of your ColdFusion folder:

    1. In version 6.0, put it in the wwwroot folder under your ColdFusion installation folder.
    2. In version 6.1, put it in the JRun4\servers\cfusion\cfusion-ear\cfusion-war folder.

Note: The sample ColdFusion Component gives you the ability to run a query statement against any ColdFusion data source that you have set up on your machine. You should install it to the web root folder only within a development environment behind a secure firewall or on a computer that is not connected to the Internet! If you intend to use this component in a production environment you must take the necessary steps to secure it.

Defining the Time Entry Application Framework

When you build an application, it's important as a developer to define a framework that works for you. Will it be a form-based application? How will users navigate it? Is there one place for data access? How easily can you add a new screen? Where do you store your code?

When I built the Time Entry sample application I asked myself these questions and came up with the answers that made sense to me. I was particularly concerned with best practices that would make it easier for me to maintain and enhance my application in the future. Being a developer myself, I also wanted to make sure I was making use of new features such as forms, data integration, and the great enhancements made to ActionScript 2.0 that would make my life easier, such as external classes and compiler type checking.

Once I learned how to use these features (some of it by trial and error) I found that they did indeed make my life much easier. I was able to develop a workflow and use features that were similar to other development environments with which I was familiar.

The type of applications I was used to building utilized a form-based metaphor. They encapsulated my UI and data access logic into separate building blocks that exposed their logic through a public interface. The new forms feature in Flash MX Professional 2004 was an excellent fit. By playing around with different options in the UI and code I was able to build the exact type of framework I was used to.

Establishing a Forms Workflow

The Time Entry sample application provides several tabs to show different views of data (see Figure 2). Each data view is represented by a form within the application. I added an additional form, called a data module, to encapsulate the data integration logic for the application. Finally, I made use of the top-level application form as a container for my application logic and UI.

Outline of the form

Figure 2. Outline of the form

I chose a Hide Screen option for each of my forms so I would only have to see the form I selected within the authoring environment.

Each form within the application is associated with a class file that encapsulates all of the necessary logic. Each class file provides public methods for services that should be exposed to other classes. (For example, the TimeEntryData class exposes a public method called addTimeEntry for creating a new time entry within the DataSet.) Table 1 defines the UI and logic contained within each form.

Notice that the class files are contained within a package (com.macromedia.timeentry) located under the src folder. Therefore, a class path (./src) has been added to the project so that the compiler can find the ActionScript class files.

Table 1. Form Modules
Form UI Logic (Provided by the Class File)
application Contains the Time Entry graphic, menu bar, toolbar, and framework for hosting UI forms Sets up the menu and responds to menu and toolbar selections
dmTimeEntry Contains nonvisual data components Encapsulates all logic for accessing, managing, and resolving data to an external data source and the local computer
frmTimeEntry Contains UI for manipulating time-entry data, including filtering, sorting, and modifying data Contains logic for setting up the UI such as controlling columns within the DataGrid, and responds to button clicks such as add, remove, save, and load
frmProject Not implemented Not implemented
frmClient Not implemented Not implemented
frmLog Contains a TextArea for viewing data packets Exposes a simple interface that other modules can call to add entries into the log view

As you can see, this sample application demonstrates the use of forms and some of the data features in Flash MX Professional 2004. It also provides a simple framework that may be useful to others as they structure and build their own applications. Look at the source code, read the comments, and review the way I use data binding to control the flow of data between components. I encourage you to build additional versions of the sample ColdFusion component in a familiar language (such as ASP.NET, Java servlets, PHP). For detailed instructions on building a server-side object that works with the format of the RDBMSResolver, read Mark Rausch's article, "Updating a Database Using Flash MX Professional 2004," which walks you through the creation of RDBMSProcessor.cfc used in this sample application.


About the author

Paul Gubbay has a 15-year background in the software industry and specializes in conversion and delivery of legacy data through the Internet. In the role of CEO, Paul spent the last several years building the vision and infrastructure of CyberSage Software. His understanding of the issues that face today's customers and the development tools available to solve them has played a key role in the direction of the company. Under Paul's guidance, CyberSage focused on emerging technologies such as XML, Java, and Macromedia Flash to deliver leading-edge product offerings. With Macromedia's technology acquisition of CyberSage Software, Paul joined Macromedia as Director of Engineering for Flash Professional, where he continues to apply his vision and understanding of customers' needs to Macromedia product offerings.